package gui.awt.listener;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//测试输入框
public class TestField {
    public static void main(String[] args) {
        //只管启动
        new MyFrame();
    }
}

class MyFrame extends Frame{
    public MyFrame(){
        TextField textField = new TextField();
        add(textField);

        MyActionListener2 myActionListener2 = new MyActionListener2();
        //监听文本框输入的文字
        textField.addActionListener(myActionListener2);

        pack();
        setVisible(true);

        //设置替换编码
        textField.setEchoChar('*');
    }
}

class MyActionListener2 implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
//        e.getSource();//获得一些资源
//        System.out.println(e.getSource());
        TextField textField = (TextField) e.getSource();
        System.out.println(textField.getText());
        textField.setText("");
    }
}
